package com.xing.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xing.dto.ViewHistoryDTO;
import com.xing.entity.ViewHistoryEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2024/4/27 16:21
 */
@Mapper
public interface ViewHistoryDao extends BaseMapper<ViewHistoryEntity> {
    @Select("SELECT vh.*, os1.url, r.info, u.nickname, os2.url as head_url\n" +
            "FROM live_view_history vh\n" +
            "         LEFT JOIN live_room r ON r.id = vh.room_id\n" +
            "         LEFT JOIN sys_user u ON u.id = r.anchor_id\n" +
            "        LEFT JOIN sys_oss os1 ON os1.id = cover_id\n" +
            "LEFT JOIN sys_oss os2 ON os2.id = u.head_url\n" +
            "WHERE vh.user_id = #{userId} AND vh.del_flag = 0 limit ${page},${limit}\n")
    List<ViewHistoryDTO> getViewHistoryList(@Param("userId") Long userId,
                                            @Param("page") Integer page,
                                            @Param("limit") Integer limit);

    @Select("SELECT COUNT(*) FROM live_view_history WHERE user_id = #{userId}")
    Integer getViewHistoryListNum(@Param("userId") Long userId);
}
